{extend name="common/base" /}
{block name="jscss"}
{CSS href="__STATIC__/admin/css/media_news.css" /}
{js href='__STATIC__/admin/ueditor/ueditor.config.js' /}
{js href='__STATIC__/admin/ueditor/ueditor.all.js' /}
{js href='__STATIC__/js/ajax_file_upload.js' /}
<style>
    #edui1_iframeholder img{ width: 100%;}
    #edui1_iframeholder{
        height: 450px !important;}
</style>
{/block}
{block name="body"}
<form class="layui-form" action="" style="padding-right: 10px;">
    <input type="hidden" name="id" value="{if isset($data)}{$data['id']}{/if}">
    <div class="layui-form-item">
        <label class="layui-form-label">分类名称</label>
        <div class="layui-input-block">
            <input type="text"
                   name="name"
                   required
                   lay-verify="required"
                   placeholder="请输入分类名称"
                   autocomplete="off"
                   value="{if isset($data)}{$data['name']}{/if}"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上级分类</label>
        <div class="layui-input-block">
            <select name="p_id">
                <option value="0" {if empty($data)}selected{/if}>顶级分类</option>
                {volist name="cateData" id="v"}
                <option value="{$v.id}" {if isset($data) && $data['p_id'] == $v['id']}selected{/if}>{$v.name}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="ADM">立即提交</button>
            <a href="{:url('category/index')}" class="layui-btn layui-btn-primary">返回</a>
        </div>
    </div>
</form>


<script>
    layui.use('form', function(){
        var form = layui.form;
        var $ = layui.jquery;
        form.on('submit(ADM)', function(data){
            $.post("{:url('category/save')}",data.field,function (res) {
                if(res.status=='0'){
                    layer.msg(res.msg);
                }
                if(res.status=='1'){
                    layer.msg(res.msg,{time:1000},function () {
                        location.href="{:url('category/index')}";
                    });
                }
            })
            return false;
        });
    });
</script>
{/block}